package com.gxc.dbcore.util;

import java.util.List;
import java.util.Map;

public class ConditionUtil {

	/**
	 * 从params中设置查询条件
	 * 
	 * @param conditionList
	 * @param params
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static List<CompareItem> setConditionValue(
			List<CompareItem> conditionList, Map params) {
		if (conditionList != null && params != null) {
			for (CompareItem item : conditionList) {
				if (item.getCompareType() == CompareType.BETWEEN) {
					if (params.get(item.getColumnName() + "__start") != null) {
						item.setCompareValue(params.get(item.getColumnName()
								+ "__start"));
					}
					if (params.get(item.getColumnName() + "__end") != null) {
						item.setCompareValue2(params.get(item.getColumnName()
								+ "__end"));
					}
				} else {
					if (params.get(item.getColumnName()) != null) {
						item.setCompareValue(params.get(item.getColumnName()));
					}
				}
			}
		}
		return conditionList;
	}

	/**
	 * 从params获取排序参数
	 * 
	 * @param params
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static String getFieldSort(Map params) {
		if (params != null) {
			return (String) params.get("fieldSort");
		}
		return null;
	}
}
